package web.staff;

import bean.Staff;
import bean.Video;
import com.alibaba.fastjson.JSON;
import entity.StaffEntity;
import entity.VideoEntity;
import util.FANREN;

import javax.persistence.EntityManager;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(name = "StaffDelete",urlPatterns = "/dao/update/staffDelete")
public class StaffDelete extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String jsonString = FANREN.getJson(request);
        System.out.println(jsonString);
        EntityManager em = (EntityManager) request.getAttribute("_entity.Manager");
        Staff staff = JSON.parseObject(jsonString,Staff.class);
        StaffEntity staffEntity = em.find(StaffEntity.class,Integer.parseInt(staff.getSid()));
        if(staffEntity!=null)
            em.remove(staffEntity);
    }
}
